<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="referrer" content="no-referrer">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <title>小众摸鱼日历API接口演示</title>
    <meta name="keywords" content="随机输出一张小众摸鱼日历图片" />
    <meta name="description" content="随机输出一张小众摸鱼日历图片" />
    <link rel="stylesheet" type="text/css" href="/css/main.min.css" />
    <link rel="stylesheet" type="text/css" href="/css/ashes.min.css" />
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 400px;
            width: 100%;
        }
        .avatar {
            margin: 20px 0;
        }
        .avatar img {
            max-width: 100%;
            border-radius: 8px;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>摸鱼日历演示</h1>
    <div class="avatar" id="avatar" >
        <p>点击下面的按钮来获取摸鱼日历。</p>
    </div>
    <div class="loading" id="loading" style="display: none;">加载中，请稍候...</div>
    <button id="getAvatarButton">获取摸鱼日历</button>
</div>

<script>

    document.getElementById('getAvatarButton').addEventListener('click', function() {
        const avatarDiv = document.getElementById('avatar');
        const loadingDiv = document.getElementById('loading');
        loadingDiv.style.display = 'block';
        loadingDiv.style.display = 'block';
        loadingDiv.style.display = 'block';
        loadingDiv.style.display = 'block';
        loadingDiv.style.display = 'block';

        fetch('https://api.vvhan.com/api/moyu?type=json')
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    loadingDiv.style.display = 'none';
                    // language=HTML
                    avatarDiv.innerHTML = `<img src="${data.url}" alt="随机摸鱼日历" />`;
                     document.getElementById('getAvatarButton').disabled = true; // 禁用按钮
                } else {
                    loadingDiv.style.display = 'none';
                    document.getElementById('avatar').innerText = '获取摸鱼日历失败，请稍后再试。';
                }
            })
            .catch(error => {
                loadingDiv.style.display = 'none';
                console.error('Error fetching the avatar:', error);
                document.getElementById('avatar').innerText = '获取摸鱼日历失败，请稍后再试。';
            });});

</script>
</body>
</html>
